package model.util;

import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import au.com.bytecode.opencsv.CSVReader;

public class RandomStandardNormal {

	List<Double>[] loadedNumbers;
	
	/**
	 * There are two different sets of 10 numbers, 250 numbers long.
	 * @param setNumber -1 or 2.
	 * @param numberOfAssets
	 * @return
	 */
	public List<Double>[] getNumbers(int setNumber, int numberOfAssets){
		
		if(loadedNumbers==null){
			try{
				CSVReader reader = new CSVReader(new InputStreamReader(RandomStandardNormal.class.getClassLoader().getResourceAsStream("randomstdnormals.csv")));
			    String [] nextLine;
			    loadedNumbers = new List[20];
			    int count=0;
			    while ((nextLine = reader.readNext()) != null) {
			    	
			        // nextLine[] is an array of values from the line
			        List<Double> line= new ArrayList<Double>();
			        loadedNumbers[count++]=line;
			        for(int i=0;i<nextLine.length;i++){
			        	line.add(new Double(nextLine[i]));
			        }
			    }
		    }catch(IOException e){
		    	throw new RuntimeException(e);
		    }
		}
		
		int start=0;
		if(setNumber==2){
			start=10;
		}
		List<Double>[] ret = new List[numberOfAssets];
		for(int i=start;i<start+numberOfAssets;i++){
			ret[i-start] = loadedNumbers[i];
		}
		return ret;
	}
}
